Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
hal_frdm_fxs_mult2_b.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NXP Semiconductor
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*! \file hal_frdm_fxs_mult2_b.c
32  \brief Hardware Abstraction layer for the FRDM-FXS-MULT2-B sensor shield.
33 */
34 
35 #include "sensor_fusion.h" // top level magCal and sensor fusion interfaces
36 
37 // This HAL (Hardware Abstraction Layer) is applicable to:
38 // FRDM_K64F +
39 // FRDM_FXS_MULT2_B utilizing the FX0S8700 and FXAS21002 on the shield
40 // It also works for the FRDM-STBC_AGM01 board.
41 // It also works for the FRDM-STBC_AGM02 board (the driver_MAG3110.c inverts
42 // the MAG3110 Z-axis reading to enforce +Z = up, so compatibility is maintained)
43 
45 {
46  int8 i; // loop counter
47 
48  // apply HAL to all measurements read from FIFO buffer
49  for (i = 0; i < Accel->iFIFOCount; i++)
50  {
51  // apply HAL mapping to coordinate system used
52 #if THISCOORDSYSTEM == NED
53  int16 itmp16 = Accel->iGsFIFO[i][CHX];
54  Accel->iGsFIFO[i][CHX] = Accel->iGsFIFO[i][CHY];
55  Accel->iGsFIFO[i][CHY] = itmp16;
56 #endif // NED
57 #if THISCOORDSYSTEM == ANDROID
58  Accel->iGsFIFO[i][CHX] = -Accel->iGsFIFO[i][CHX];
59  Accel->iGsFIFO[i][CHY] = -Accel->iGsFIFO[i][CHY];
60 #endif // Android
61 #if (THISCOORDSYSTEM == WIN8)
62  Accel->iGsFIFO[i][CHZ] = -Accel->iGsFIFO[i][CHZ];
63 #endif // Win8
64 
65  } // end of loop over FIFO count
66 
67  return;
68 }
69 
70 // function applies the hardware abstraction layer to the magnetometer readings
72 {
73  int8 i; // loop counter
74 
75  // apply HAL to all measurements read from FIFO buffer
76  for (i = 0; i < Mag->iFIFOCount; i++)
77  {
78  // apply HAL mapping to coordinate system used
79 #if THISCOORDSYSTEM == NED
80  int16 itmp16 = Mag->iBsFIFO[i][CHX];
81  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHY];
82  Mag->iBsFIFO[i][CHY] = -itmp16;
83  Mag->iBsFIFO[i][CHZ] = -Mag->iBsFIFO[i][CHZ];
84 #endif // NED
85 #if THISCOORDSYSTEM == ANDROID
86  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
87  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
88 #endif // Android
89 #if THISCOORDSYSTEM == WIN8
90  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
91  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
92 #endif
93  } // end of loop over FIFO count
94 
95  return;
96 }
97 
98 // function applies the hardware abstraction layer to the gyro readings
100 {
101  int8 i; // loop counter
102 
103  // apply HAL to all measurements read from FIFO buffer
104  for (i = 0; i < Gyro->iFIFOCount; i++)
105  {
106  // apply HAL mapping to coordinate system used
107 #if THISCOORDSYSTEM == NED
108  int16 itmp16 = Gyro->iYsFIFO[i][CHX];
109  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHY];
110  Gyro->iYsFIFO[i][CHY] = -itmp16;
111  Gyro->iYsFIFO[i][CHZ] = -Gyro->iYsFIFO[i][CHZ];
112 #endif // NED
113 #if THISCOORDSYSTEM == ANDROID
114  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
115  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
116 #endif // Android
117 #if THISCOORDSYSTEM == WIN8
118  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
119  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
120 #endif // Win8
121 
122  } // end of loop over FIFO count
123 
124  return;
125 }
126 
int16_t iGsFIFO[ACCEL_FIFO_SIZE][3]
FIFO measurements (counts)
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
uint8_t iFIFOCount
number of measurements read from FIFO
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
void ApplyGyroHAL(GyroSensor *Gyro)
Apply the gyroscope Hardware Abstraction Layer.
The sensor_fusion.h file implements the top level programming interface.
#define CHZ
uint8_t iFIFOCount
number of measurements read from FIFO
int16_t iYsFIFO[GYRO_FIFO_SIZE][3]
FIFO measurements (counts)
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
uint8_t iFIFOCount
number of measurements read from FIFO
void ApplyAccelHAL(AccelSensor *Accel)
Apply the accelerometer Hardware Abstraction Layer.
int16_t iBsFIFO[MAG_FIFO_SIZE][3]
FIFO measurements (counts)
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
int16_t int16
Definition: sensor_fusion.h:56
void ApplyMagHAL(MagSensor *Mag)
Apply the magnetometer Hardware Abstraction Layer.
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
int8_t int8
Definition: sensor_fusion.h:55